package cn.lg.soar.message.feign;


import cn.lg.soar.core.annotations.ApiClient;
import cn.lg.soar.message.api.constant.ModuleConst;
import cn.lg.soar.message.api.model.MailDTO;
import cn.lg.soar.message.api.service.IMailApi;
import cn.lg.soar.message.feign.fallback.MailApiFallbackFactoryFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingClass;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

import java.time.Duration;

/**
 * @author luguoxiang
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@ConditionalOnMissingClass("cn.lg.soar.message.client.MailApiClient")
@ApiClient
@FeignClient(
        name=ModuleConst.MODULE_NAME,
        path= ModuleConst.CLIENT_PATH + "/mail",
        fallbackFactory= MailApiFallbackFactoryFactory.class,
        contextId = "MailApiFeign"
)
public interface MailApiFeign extends IMailApi {

    @PostMapping("send")
    @Override
    void send(@RequestBody MailDTO mail);

    @PostMapping("sendMail")
    @Override
    void sendCaptcha(
            @RequestParam("email") String email,
            @RequestParam("subject") String subject,
            @RequestParam("expire") Duration expire,
            @RequestParam("captcha") String captcha
    );

    @GetMapping("checkMail")
    @Override
    boolean checkCaptcha(
            @RequestParam("email") String email,
            @RequestParam("captcha") String captcha,
            @RequestParam("delete") Boolean delete
    );

}
